/**
 * 用户列表返回数据项
 */
interface UserListItemResponse{
    /**
     * 主键
     */
    userId:string;
    /**
     * 序号
     */
    index: number;
    /**
     * 实名认证状态
     */
    realNameState:number;
    /**
     * 真实姓名
     */
    realName:string;
    /**
     * 电话号码
     */
    phoneNumber:string;
    /**
     * 是否启用
     */
    isLockedout:boolean;
    /**
     * 认证时间
     */
    certificationTime:string;
    /**
     * 车长
     */
    carLength:string;
    /**
     * 用户名
     */
    userName:string;
    /**
     * 车型
     */
    carType:string;
    /**
     * 车牌号
     */
    carNumber:string;
    /**
     * 角色
     */
    roles:string;
}

/**
 * 用户详细
 */
interface UserDetailRespose extends BaseResponse{
    /**
     * 车牌号
     */
    carCode:string;
    /**
     * 驾驶证
     */
    drivingLicenseImage:string;
    /**
     * 驾驶证状态
     */
    drivingLincenseState:number;
    /**
     * 身份证
     */
    idCardImage:string;
    /**
     * 身份证状态
     */
    idCardState:number;
    /**
     * 实名头像
     */
    realHeadImage:string;
    /**
     * 实名头像状态
     */
    realHeadState:number;
    /**
     * 实名头像认证状态
     */
    state:number;
    /**
     * 行驶证
     */
    vehicleLicenseImage:string;
    /**
     * 行驶证状态
     */
    vehicleLicenseState:number;
    /**
     * 说明
     */
    message:string;

}

/**
 * 用户服务
 */
interface IUserService{
    /**
     * 获取列表
     * @param keyWord 关键字
     * @param carCode 车牌号
     * @param startTime 起始时间
     * @param endTime 结束时间
     * @param roleId 角色
     * @param state 实名认证状态
     * @param useCache 缓存（默认为true）
     */
    getList(keyWord: string, carCode: string, startTime: Date, endTime: Date, roleId: string, state: number, useCache:boolean, skip: number, count: number): ng.IHttpPromise<ListResponse<UserListItemResponse>>;

    /**
     * 获取详细
     * @param userId 用户编号
     */
    getDetail(userId:string):ng.IHttpPromise<UserDetailRespose>;

    /**
     * 启用禁用
     * @param userId 用户编号
     * @param disabled是否启用（默认为true）
     */
    setAccountLockoutState(userId: string, disabled: boolean):ng.IHttpPromise<BaseResponse>;

    /**
     * 编辑实名认证状态
     * @param userId 用户编号
     * @param carCode 车牌号
     * @param drivingLincenseKeyStatus 驾驶证状态
     * @param idCardKeyStatus 身份证状态
     * @param realHeadKeyStatus 实名头像状态
     * @param vehicleLicenseKeyStatus 驾驶证状态
     */
    putUserRealNameCertificationStatus(userId: string, carCode: string, drivingLincenseKeyStatus: number, idCardKeyStatus: number, realHeadKeyStatus: number,vehicleLicenseKeyStatus:number): ng.IHttpPromise<BaseResponse>;

}

class userService implements IUserService{
    constructor(private http: ng.IHttpService,private route: routeService){
    }


    getList(keyWord: string, carCode: string, startTime: Date, endTime: Date, roleId: string, state: number, useCache:boolean, skip: number, count: number): ng.IHttpPromise<ListResponse<UserListItemResponse>>{
        return this.http<ListResponse<UserListItemResponse>>({
            method:"GET",
            url:this.route.getUrl("users?keyWord={{keyWord}}&carCode={{carCode}}&startTime={{startTime}}&endTime={{endTime}}&roleId={{roleId}}&state={{state}}&useCache={{useCache}}&skip={{skip}}&count={{count}}",{
                keyWord:keyWord,
                carCode:carCode,
                startTime:startTime,
                endTime:endTime,
                roleId:roleId,
                state:state,
                useCache:useCache,
                skip: skip,
                count: count
            })
        });
    }

    getDetail(userId:string):ng.IHttpPromise<UserDetailRespose>{
        return this.http<UserDetailRespose>({
            method:"GET",
            url:this.route.getUrl("users/{{userId}}",{
                userId: userId
            })
        });
    }

    setAccountLockoutState(userId: string, disabled: boolean):ng.IHttpPromise<BaseResponse>{
        return this.http<BaseResponse>({
            method:"GET",
            url:this.route.getUrl("users/{{userId}}/enabled?disabled={{disabled}}",{
                userId: userId,
                disabled: disabled
            })
        })
    }

    putUserRealNameCertificationStatus(userId: string, carCode: string, drivingLincenseKeyStatus: number, idCardKeyStatus: number, realHeadKeyStatus: number,vehicleLicenseKeyStatus:number): ng.IHttpPromise<BaseResponse>{
        return this.http<BaseResponse>({
            method:"PUT",
            url:this.route.getUrl("users/{{userId}}",{
                userId:userId
            }),
            data:{
                carCode: carCode,
                drivingLincenseKeyStatus: drivingLincenseKeyStatus,
                 idCardKeyStatus: idCardKeyStatus, 
                 realHeadKeyStatus: realHeadKeyStatus,
                 vehicleLicenseKeyStatus: vehicleLicenseKeyStatus
            }
        })
    }
    
    
    
}

app.service("userService",['$http','routeService',userService]);